package juc.c_020;/*
   Talk is cheap. Show me the code.
 */

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Description
 * @Date 2021/6/18
 * @Author liudl
 */
public class T07_Cyclibarrier {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(10,()-> System.out.println("满员发车！"));
        for (int i = 0; i < 50; i++) {
            new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName());
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
